﻿Imports CoreFX
Imports System
Imports System.Threading
Imports System.Runtime.Remoting
Imports Microsoft.VisualBasic.Compatibility
Namespace AppDomains
    Public Class ConnectionBroker
        Shared Event ADError(ByVal exception As String)
        Shared Event ADConnected(ByVal ServerName As String)
        Shared WithEvents adChatClient As CoreFX.AppDomains.ConnectionWorker
        Private Sub New()
            RemotingConfiguration.Configure("client.exe.config", False)
            'FChatter = New Chatter
            'AddHandler FChatter.MessageEvent, AddressOf OnMessageEvent
        End Sub
        Public Shared Sub CreateNewConnection(ByVal ServerName As String, ByVal Address As String, ByVal Username As String, ByVal Password As String, ByVal Port As String, ByVal ChanWin As Object)
            Dim s As New ChatEngine.ServerManagement.Server
            s.username = Username
            s.password = Password
            s.address = Address
            s.name = ServerName
            s.port = Port
            CreateNewConnection(s, ChanWin)
        End Sub
        Public Shared Sub CreateNewConnection(ByVal Server As ChatEngine.ServerManagement.Server, ByVal ChanWin As Object)
            Dim AD As System.AppDomain = System.AppDomain.CreateDomain(Server.name)
            Dim Assy As System.Reflection.Assembly
            adChatClient = CType(AD.CreateInstanceAndUnwrap("mchat", "CoreFX.AppDomains.ConnectionWorker"), CoreFX.AppDomains.ConnectionWorker)
            adChatClient.ConnectToServer(Server, Nothing)
            'AddHandler adChatClient.Client.AddLineToConsole, AddressOf ALTC
            Assy = Nothing
        End Sub
        Private Shared Sub ALTC(ByVal Info As String)
            MsgBox("HI")
        End Sub
    End Class
End Namespace
